package com.dts.yjnb.service.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 定时任务类
 *
 * @author dts
 */
@Component
@Slf4j
public class task {

    /**
     * 每秒打印当前秒数
     * cron表达式: 0/1 * * * * ? 表示每秒执行一次
     */
    //@Scheduled(cron = "0/1 * * * * ?")
    public void printCurrentSecond() {
        LocalDateTime now = LocalDateTime.now();
        int second = now.getSecond();
        String timeStr = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info("当前秒数: {} (时间: {})", second, timeStr);
    }
}
